package com.ido.switchmodel

import com.ido.switchmodel.hot.SMHotInterface
import kotlin.jvm.Volatile

/**
 * 工程处理
 */
class SMHolder private constructor() {

    private var factoryProxy: SmFactoryProxy? = null

    companion object {
        //声明类的变量
        @Volatile
        private var sManager: SMHolder? = null

        //暴露外界访问的方法,双层锁
        //创建对象
        //如果不等于空直接返回对象,符合单例的概念+
        fun getInstance(): SMHolder {
            if (sManager == null) {
                synchronized(SMHolder::class.java) {
                    if (sManager == null) {
                        sManager = SMHolder()
                    }
                }
            }
            return sManager!!
        }
    }

    private fun createFactory() {
        if (factoryProxy == null) {
            factoryProxy=SmFactoryProxy()
        }
    }

    fun getHotSplash(): SMHotInterface {
        createFactory()
        return factoryProxy!!.getHotSplash()
    }

}